Skip to content

Report Swing components and SwingNode misuse - #44

Merged
Ivan Matkov (MatkovIvan) merged 15 commits into
masterfrom
ivan.matkov/composable-signature-rules
Nov 17, 2026
Merged

Ivan Matkov (MatkovIvan) merged 15 commits into
masterfrom
ivan.matkov/composable-signature-rules

Conversation

@MatkovIvan

@MatkovIvan Ivan Matkov (MatkovIvan) commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator
  • SwingComponentLibraryApi
    • A warning-level opt-in marks the API for writing components: SwingNode, ExistingSwingNode, MenuNode and VirtualSwingNode.
    • The factory overloads of ScrollPane, ListBox, Table and Tree are public API under this marker.
  • swing-ui-detekt rules
    • SwingComponentInComposableSignature and MultipleSwingModifierParameters report a Swing component in a composable signature and a second SwingModifier parameter.
    • SwingNodeFactoryReusesComponent, SwingNodeFactoryReadsDeclaredValue and MultipleSwingNodeCalls report a factory that reuses a component, a factory that reads a value update never applies, and several node calls in one composable.
    • SwingNodeUpdateWritesComponentPart, SwingNodeUpdateRepeatsInvalidation, SwingNodeUpdateStoresCallback and SwingNodeUpdateConditionalCall report an update that writes a part the component builds itself, repeats a request its setters make, stores a callback a self-listener reads, or calls the updater conditionally.
    • Every finding message of the existing rules says what is wrong, why, and what to change.
    • PreferImportsOverFqn also reports fully qualified calls and references.
  • swing-ui-test
    • onAllRoots() lists the roots; onRoot() fails when there are several.
    • Finders search content composed in nested compositions, such as a popup menu.

Layout code can call SwingNode, MenuNode, VirtualSwingNode and ExistingSwingNode with no signal that
they are meant for writing components. A Swing component placed directly in a layout keeps its layout,
state and listeners out of the composition's reach.

SwingComponentLibraryApi marks API for writing components, as a warning-level opt-in. It marks the
SwingNode, MenuNode, VirtualSwingNode and ExistingSwingNode composables, and the factory overloads of
ScrollPane, ListBox, Table and Tree, which move from InternalSwingUiApi to it. Its message tells layout
code to use component composables, and to wrap a Swing component that has no composable in its own
composable. The library modules and the sample modules opt in to it, and so do the test sources of
swing-ui-test and the benchmark modules.
@MatkovIvan
Ivan Matkov (MatkovIvan) force-pushed the ivan.matkov/composable-signature-rules branch 3 times, most recently from 6ba7e93 to f9bceb9 Compare November 17, 2026 12:54
The finders searched only the harness root, so content set on a free host or in a composed popup menu was invisible to them.

Content compositions now announce themselves to the test harness through the effect context, and the finders search the harness root plus every such root outside a window. onAllRoots() lists them and onRoot() fails naming their count when there are several.
A composable that takes or hands back a Swing component makes its caller own an object that the
composition is meant to build, hold and release itself. It also ties the composable to one instance.

The rule reports a named composable, a composable property getter, or a composable function type whose
signature names java.awt.Component or a subclass. It searches the parameters, the extension receiver,
the context parameters, the return type and the type-parameter bounds, through nullability, type
arguments and function types at any depth. It also covers a generic type alias that expands to a
composable function type. It leaves out an override at a position where the declaration it overrides
already names a component, an actual declaration, and declarations marked SwingComponentLibraryApi with
the members of a class marked with it. It runs only under the type-resolving
tasks.

Internal composables that took a component, or a reader typed over one, now take what they read from it:
the lifecycle owner resolution of the content's host, the window, a callback that publishes composition
data, and the declared combo box items. The spinner editor and the content-parent publication are composed
inline.
…r parameter

A composable that takes two modifier chains leaves a caller unable to tell which part of the content each
chain styles. The composable has no single root to hold both, so one of the chains has nowhere to go.

The rule reports each SwingModifier parameter after the first one of a composable or of a composable
function type. It counts value and context parameters at any visibility. It leaves out overrides and actual
declarations, along with the function types in their signatures, and any parameter whose type does not resolve.

Each test composable now takes one modifier parameter.
…nent

A node calls its factory each time it creates a node. A factory that returns a component declared outside
itself gives every node the same instance, and a node that was replaced can still drive that instance.

The rule reports a SwingNode or MenuNode factory lambda that returns a name, this, or a property access
declared outside the lambda. It leaves out calls, including custom factory functions, and factories passed
as anything other than a lambda literal.
…its composable declares

A node runs its factory once, when it is created, so a value that the factory reads reaches the
component only then. A later change of that value does not reach the component unless update applies it.

The rule reports a SwingNode or MenuNode factory lambda that reads a value parameter of the enclosing
named composable, or of a lambda around the node, including an implicit it. It reports each parameter
once per factory, at its first reference. It leaves out locals, class properties, members of anonymous
objects and values that the factory declares itself. It also leaves out a function-typed parameter that
the factory invokes, a parameter that a set or update call applies as a direct statement of update, and
a parameter that the keys of a key call around the node name. It runs only under the type-resolving
tasks.
…hadowing and resolve an aliased Composable import

The modifier factory rules read a bare `SwingModifier` as the companion even where a property of an enclosing
class, object or companion named `SwingModifier` is in scope, so they reported a factory that never touches the
companion. The rules that check composables matched `Composable` by its short name only, so a
composable whose annotation is imported under an alias was not checked.

A bare `SwingModifier` now counts as shadowed by a property of every enclosing class or object whose members code
at that depth can reach. `Composable` is also recognized under an import alias, unless an enclosing class declares
a class of that name.
…t only types

PreferImportsOverFqn read syntax alone, which cannot tell a package from a value receiver, so it checked
only type references and let a fully qualified call such as `org.jetbrains.compose.swing.node.SwingNode(...)`
pass. The rule now resolves the leftmost qualifier and also reports a call or reference chain that starts at a
package. A chain that starts at a value is never reported, and the rule runs only under the type-resolving
tasks.

The library and test code it reports now import the names instead.
…than once

SwingNode brings one component from a component library into the composition. A composable that calls it
more than once builds its layout from raw Swing components and mixes them with composables in one function.
The composition does not know what those components are, so their layout, state and listeners stay in Swing,
and a place that holds exactly one component, such as a tab header, refuses the second one.

The rule reports each SwingNode or MenuNode call after the first one in a named composable, including calls
in nested lambdas and in every branch of an if, when or try. It leaves out local functions, classes and
objects, composable lambdas outside a named function, and ExistingSwingNode calls.

RadioGroup and the test fixtures give each component its own composable.
…f a source-built component

A composite panel that is assembled in Swing and hosted as one node hides its parts from the composition.
No modifier, test tag or style reaches those parts, and the update block must push their values by hand.

The rule reports an update block that writes a child property of a component class declared in the same
module, when the class builds that child itself in an initializer. It leaves out library and JDK components,
parts that a constructor hands in, delegated parts, reads, and writes made inside a scope function.
…st its writes already make

An invalidation call that follows a write which already requests the same layout or paint adds a second
request on every change. It also suggests that the component's setter does not make the request when it
does, which misleads the next reader.

The rule reports a revalidate, invalidate or repaint call in a set or update block of a SwingNode or
MenuNode when the block's other statements are writes whose JDK setters already make that request. It
leaves out blocks with any other statement, writes the rule does not know, and validate and doLayout.
…ck a self-listener reads

A component that registers a listener on itself while it is built keeps that listener after its node is
released. Such a listener keeps calling the last callback that an update stored in a property of the
component. A listener modifier, by contrast, is removed when the node is released.

The rule reports a set or update block of a SwingNode or MenuNode that assigns a function-typed property
of its component when the component registers a listener on itself while it is built, and that listener
reads the property. It leaves out component classes from a library or the JDK, since the rule reads the
class source. It also leaves out registrations made in with, in a part of the component, or after the
component is built, and a listener that reaches the callback through a member function it calls. Each
assignment is reported once, at the assignment.
…direct statement of update

A set, update or declare call that sits under a condition, a loop, a try or a lambda, or that follows an
early return, can be skipped on a recomposition. The updater matches these calls to the previous
recomposition by their order, so a skipped call makes the later calls compare against values recorded for
other calls.

The rule reports a positional set, update or declare call on the updater that is not a direct statement
of update, or that comes after an early return from update. The one exemption is a call inside the block
lambda of another positional call. It runs only under the type-resolving tasks.
…finding matters and what to change

The modifier, table and animation rules reported what they matched without saying why it matters or what to
write instead, so a developer had to read the rule's source to act on a finding.

Each message now states what is wrong at the site, why it matters, and the change to make. The rule
descriptions become one-line titles.
@MatkovIvan
Ivan Matkov (MatkovIvan) force-pushed the ivan.matkov/composable-signature-rules branch 2 times, most recently from 272c41c to 1b8fc6a Compare November 17, 2026 14:47
@MatkovIvan
Ivan Matkov (MatkovIvan) merged commit 1b8fc6a into master Nov 17, 2026
4 checks passed
@MatkovIvan
Ivan Matkov (MatkovIvan) deleted the ivan.matkov/composable-signature-rules branch November 17, 2026 15:11

This branch was previously deployed

1 inactive deployment
github-pages — 1b8fc6ad Deployed Nov 17, 2026 by MatkovIvan via Publish API Reference #54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant